﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Sprout.Core.Paging
{
    /// <summary>
    /// 分页基类
    /// </summary>
    public abstract class PageParameter
    {
        //开始页数
        private int startPageIndex = 1;

        private int pageIndex = 0;
        /// <summary>
        /// 当前页
        /// </summary>
        public int PageIndex
        {
            get
            {
                if (pageIndex < startPageIndex)
                {
                    return pageIndex = startPageIndex;
                }
                return pageIndex;
            }
            set
            {
                pageIndex = value;
            }
        }
        private int pageSize = 0;
        /// <summary>
        /// 每页条数
        /// </summary>
        public int PageSize
        {
            get
            {
                return pageSize;
            }
            set
            {
                pageSize = value;
            }
        }

        /// <summary>
        /// 记录开始行号，1开始。
        /// </summary>
        public int StartIndex
        {
            get
            {
                if (offset < 0)
                {
                    return (PageIndex - startPageIndex) * PageSize + 1;
                }
                else
                {
                    return offset + 1;
                }
            }
        }

        /// <summary>
        /// 记录结束行号
        /// </summary>
        public int EndIndex
        {
            get
            {
                if (offset < 0)
                {
                    return (PageIndex - startPageIndex + 1) * PageSize;
                }
                else
                {
                    return offset + PageSize;
                }
            }
        }

        /// <summary>
        /// 跳过索引, 0开始
        /// </summary>
        public int SkipIndex
        {
            get
            {
                if (offset < 0)
                {
                    return (PageIndex - startPageIndex) * PageSize;
                }
                else
                {
                    return offset;
                }
            }
        }

        private int offset = -1;
        /// <summary>
        /// 偏移量 0开始
        /// </summary>
        public int Offset
        {
            get
            {
                return offset;
            }
            set
            {
                offset = value;
            }
        }
    }
}
